<template lang="pug">
  el-drawer.commonDrawer(
    title="新增考勤机"
    :visible="visibleDialog"
    append-to-body
    center
    destroy-on-close
    direction="rtl"
    size="640px"
    @close="$_handleCancel"
  )
    .drawer-content
      form-box(
        ref="basicForm"
        :fields="basicField"
        :showBtns="false"
        :layoutCol="{ xs: 24, md: 24, lg: 24 }"
      )
    .drawer-footer.tr
      el-button.gradientVertical(size="large" :loading="submitting" @click="submitHandle" round) 确定
</template>
<script>
import { addSubmit } from './api'

export default {
  props: {
    id: {
      type: String,
      default: ''
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      submitting: false
    }
  },
  computed: {
    visibleDialog: {
      get () {
        return this.visible
      },
      set (val) {
        this.$emit('update:visible', val)
      }
    },
    basicField () {
      return [
        {
          label: '位置',
          key: 'address',
          rules: [{ required: true, message: '请输入' }]
          // initialValue: detail.channelId,
        },
        {
          label: '序列号',
          key: 'serialNO',
          rules: [{ required: true, message: '请输入' }]
        }
      ]
    }
  },
  created () {
  },
  methods: {
    // 提交
    async submitHandle () {
      const values = await this.$refs.basicForm.submitForm()
      console.log(values)
      this.submitting = true
      addSubmit({
        id: this.id,
        ...values
      }).then(() => {
        this.$emit('getList')
        this.$_handleCancel()
        this.$message.success('保存成功')
      }).finally(() => {
        this.submitting = false
      })
    },
    $_handleCancel () {
      this.visibleDialog = false
    }
  }
}
</script>
